﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace LightCAD.Core
{
    public class LcBuilding : LcObject,IModelSite
    {
        public string Uuid { get; set; }
        public string Name { get; set; }
        public LcLevelCollection Levels { get; set; }= new LcLevelCollection();

        public ListEx<IModelGroup> Groups => Levels.ToArray().Cast<IModelGroup>().ToListEx();

        public Transform3d Transform { get; }=new Transform3d();

        public IModelSite AddGroups(params IModelGroup[] groups)
        {
            for (int i = 0; i < groups.Length; i++)
                this.Levels.Add(groups[i] as LcLevel);
            return this;
        }

        public override void ReadObjectRefs<T>(ICollection<T> objs)
        {
            base.ReadObjectRefs(objs);
            foreach (var lvl in this.Levels)
            {
                lvl.ReadObjectRefs(objs);
            }
        }
    }

    public class BuildingCollection : KeyedCollection<long, LcBuilding>
    {
        protected override long GetKeyForItem(LcBuilding item)
        {
            return item.Id;
        }
    }
}